// ==UserScript==
// @name         键盘打开超链接
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://*/*
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var select_url = null;

    document.onkeydown = function(e) {
        if (e.keyCode === 86) {
            var selecter = window.getSelection().toString();
            if (selecter.trim() != '') select_url = selecter;
            if (!select_url) return;
            if (/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/.test(select_url))
                window.open(select_url)
            else {
                window.open('https://www.baidu.com/s?wd=' + selecter)
            }
        }
    }
    /*
    $(document).mouseover(function(e) {
        if ($(e.target)[0].tagName === 'A') {
            //window.getSelection().removeAllRanges();
            select_url = $(e.target)[0].href;
        }
    });*/

})();